﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Data;
using Telerik.Windows.Controls;

namespace MedLink2011.Views.Patients.Controls.FirstLook.Converters
{
    public class CategoryToToolbarBackgroundConverter : IValueConverter
    {
        private static Color GetColorFromCode(string value)
        {
            byte byA = System.Convert.ToByte(value.Substring(1, 2), 16);
            byte byR = System.Convert.ToByte(value.Substring(3, 2), 16);
            byte byG = System.Convert.ToByte(value.Substring(5, 2), 16);
            byte byB = System.Convert.ToByte(value.Substring(7, 2), 16);
            Color c = Color.FromArgb(byA, byR, byG, byB);
            return c;
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            GradientStopCollection collection = new GradientStopCollection();
            GradientStop stop1 = new GradientStop();
            stop1.Offset = 0;
            GradientStop stop2 = new GradientStop();
            stop2.Offset = 1;
            stop1.Color = GetColorFromCode("#FF9FA6F4");
            stop2.Color = GetColorFromCode("#FF9FA6F4");
           
            if (value!=null && value is Category)
            {
                switch (((Category)value).CategoryName)
                {
                    case "Ocean":
                        stop1.Color = GetColorFromCode("#FF24A8E8");
                        stop2.Color = GetColorFromCode("#FF24A8E8");
                        break;
                    case "Disco":
                        stop1.Color = GetColorFromCode("#FFCE1371");
                        stop2.Color = GetColorFromCode("#FFCE1371");
                        break;
                    case "Relax":
                        stop1.Color = GetColorFromCode("#FFB2D264");
                        stop2.Color = GetColorFromCode("#FF8CC351");
                        break;
                    case "Orange":
                        stop1.Color = GetColorFromCode("#FFFFE077");
                        stop2.Color = GetColorFromCode("#FFFFE077");
                        break;
                        
                    default: break;
                }
                
            }
            collection.Add(stop1);
            collection.Add(stop2);
            LinearGradientBrush brush = new LinearGradientBrush(collection, 90);
            brush.StartPoint = new Point(0.5, 0);
            brush.EndPoint = new Point(0.5, 1);
            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

    }
}
